package com.heima.wemedia.controller.v1;



import com.heima.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmSensitiveDto;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.wemedia.service.WmSensitiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文本检测
 */

@RestController
@RequestMapping("/api/v1/sensitive")
public class WmSensitiveController {
    @Autowired
    private WmSensitiveService wmSensitiveService;

    /**
     * 查询所有频道
     */
    @PostMapping("/list")
    public ResponseResult findSensitiveList(@RequestBody WmSensitiveDto dto){
        return wmSensitiveService.findSensitive(dto);
    }

    /**
     * 删除违规词
     * @param id
     * @return
     */
    @DeleteMapping("del/{id}")
    public ResponseResult deleteSensitive(@PathVariable Long id){

         return wmSensitiveService.deleteSensitiveById(id);
//       return ResponseResult.okResult(wmSensitiveService.removeById(id));
    }

    /**
     * 增加违规词
     * @param wmSensitive
     * @return
     */
    @PostMapping("save")
    public ResponseResult saveSensitive(@RequestBody WmSensitive wmSensitive){
        return wmSensitiveService.saveSensitive(wmSensitive);
    }

    /**
     * 修改违规词
     * @param sensitive
     * @return
     */
    @PostMapping("update")
    public ResponseResult updateSensitive(@RequestBody WmSensitive sensitive) {
        return wmSensitiveService.updateSensitiveById(sensitive);
//        return ResponseResult.okResult(wmSensitiveService.updateById(sensitive));
    }

    /**
     * 查询所有违规词并存储在Redis
     */
    @GetMapping("/findAll")
    public ResponseResult<List<String>> findAllAndRedis(){
        return wmSensitiveService.findAllAndRedis();
    }
}